package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/16 18:26
 * @version  V1.0
 * @description:
 *
 */
func main() {
	var arr [4][6]int
	arr[1][2] = 1
	arr[2][1] = 2
	arr[2][3] = 3

	/**
	0 0 0 0 0 0
	0 0 1 0 0 0
	0 2 0 3 0 0
	0 0 0 0 0 0
	*/
	//len(arr)=4
	for i := 0; i < len(arr); i++ {
		//len(arr[i]=6
		for j := 0; j < len(arr[i]); j++ {
			fmt.Printf("%v ", arr[i][j])
		}
		fmt.Println()
	}

	//内存布局
	//var arr2 [2][3]int = [2][3]int{{1, 2, 3}, {4, 5, 6}}
	//var arr2 [2][3]int = [...][3]int{{1, 2, 3}, {4, 5, 6}}
	//var arr2 = [2][3]int{{1, 2, 3}, {4, 5, 6}}
	//var arr2 = [...][3]int{{1, 2, 3}, {4, 5, 6}}
	arr2 := [...][3]int{{1, 2, 3}, {4, 5, 6}}
	fmt.Println(arr2)

	//arr2[0]address=0xc00000c300  arr2[1]address=0xc00000c318  相差24,刚好是3个整形占用的字节
	fmt.Printf("arr2[0]address=%p  arr2[1]address=%p\n", &arr2[0], &arr2[1])
	//arr2[0][0]address=0xc00000c300  arr2[1][0]address=0xc00000c318
	fmt.Printf("arr2[0][0]address=%p  arr2[1][0]address=%p\n", &arr2[0][0], &arr2[1][0])
	//arr2[0][0]address=0xc00000c300  arr2[0][1]address=0xc00000c308 证明一个元素占用8个字节
	fmt.Printf("arr2[0][0]address=%p  arr2[0][1]address=%p\n", &arr2[0][0], &arr2[0][1])

	/**
	arr3[0][0]=1 arr3[0][1]=2 arr3[0][2]=3
	arr3[1][0]=4 arr3[1][1]=5 arr3[1][2]=6
	*/
	//遍历二维数组
	arr3 := [...][3]int{{1, 2, 3}, {4, 5, 6}}
	//way1 遍历所有的一维数组
	for i := range arr3 {
		//拿到具体的一维数组
		for j := range arr3[i] {
			//输出一维数组并且换行
			fmt.Printf("arr3[%v][%v]=%v ", i, j, arr3[i][j])
		}
		fmt.Println()
	}

	/**
	1 2 3
	4 5 6
	*/
	//way2
	for i := 0; i < len(arr3); i++ {
		for j := 0; j < len(arr3[i]); j++ {
			fmt.Printf("%v ", arr3[i][j])
		}
		fmt.Println()
	}

	/**
	arr3[0][0]=1 arr3[0][1]=2 arr3[0][2]=3
	arr3[1][0]=4 arr3[1][1]=5 arr3[1][2]=6
	*/
	//way3
	for i, v := range arr3 {
		for j, v2 := range v {
			fmt.Printf("arr3[%v][%v]=%v ", i, j, v2)
		}
		fmt.Println()
	}

}
